﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProtoGame.GameLib.Entities;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace ProtoGame.Sprites
{
    class PGSpritePlaca : BasicSprite
    {
        StringSprite numero;

        public override Microsoft.Xna.Framework.Vector2 Position
        {
            get
            {
                return base.Position;
            }
            set
            {
                base.Position = value;
                CalculaPosicaoNumero();
            }
        }

        public override float LayerDepth
        {
            get
            {
                return base.LayerDepth;
            }
            set
            {
                base.LayerDepth = value;
                if (numero != null)
                    numero.LayerDepth = value - 0.00001f;
            }
        }

        public override byte Fade
        {
            get
            {
                return base.Fade;
            }
            set
            {
                base.Fade = value;
                if (numero != null)
                    numero.Fade = value;
            }
        }

        public int Numero
        {
            set { numero.Text = value.ToString(); }
        }

        public PGSpritePlaca(SpriteFont font, Texture2D gfx)
            : base(gfx)
        {
            numero = new StringSprite(font);

            //numero.ColorEffects = Color.Black;
            Numero = -1;
            Alive = false;
            Visible = false;
            CollisionType = TiposColisoes.Nenhum;
        }

        private void CalculaPosicaoNumero()
        {
            if (numero != null)
            {
                Vector2 centroNumero = numero.MeasureString / 2;
                Vector2 centroSprite = new Vector2(Bounds.Center.X, Bounds.Center.Y);

                numero.Position = centroSprite - centroNumero;
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            numero.Draw(spriteBatch);

            base.Draw(spriteBatch);
        }
    }
}
